<template>
  <div class='search'>
    <f-drawer ref='orderDrawer' title='订单审核详情' okText='审批' :show-footer='applyMode' @submit='handleSubmit' width='88%' @visibleChange='visibleChange'>
      <hy-order-approve ref='form1' :applyMode='applyMode' v-if='drawerVisible' style='margin-bottom: 50px'></hy-order-approve>
      <task-todo-form-modal :applyMode='applyMode' ref='taskTodoFormModal' handler-name='hyOrderTaskDataHandler' task-handler-name='hyOrderTaskDataHandler' @callback='handleSuccess'></task-todo-form-modal>
    </f-drawer>
  </div>
</template>
<script>
import HyOrderApprove from "./hyorder_approve"
import TaskTodoFormModal from "@/views/module/haiying/tasktodo/tasktodo_form_modal"

export default {
  name: "HyOrderApproveDrawer",
  props: {
    applyMode: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      refs: this.$refs,
      drawerVisible: false,
      isEdit: false,
      title: "",
      current: "form1",
      formData: {},
      forms: [
        "form1"
      ]
    }
  },
  methods: {
    showDrawer(data) {
      this.isEdit = false
      if (data && data.orderId) {
        this.isEdit = true
        this.formData = data
      } else {
        this.formData = {}
      }
      this.refs["orderDrawer"].show()
      this.tabClick("form1")
    },
    visibleChange(drawerVisible) {
      this.drawerVisible = drawerVisible
    },
    tabClick(name) {
      this.current = name
      if (this.current === "form1") {
        this.title = "订单审核"
      }
      this.$nextTick(() => {
        this.refs[this.current].setData(this.formData)
      })
    },
    handleSuccess() {
      this.$refs.orderDrawer.close()
      this.$emit("success", true)
    },
    handleSubmit() {
      this.$refs.taskTodoFormModal.open(this.formData)
    }
  },
  computed: {
    drawerTitle: function() {
      return this.title
    }
  },
  created() {
  },
  components: { TaskTodoFormModal, HyOrderApprove }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
